const key = "VUE-CHAT-v3";

// 虚拟数据
if (!localStorage.getItem(key)) {
  let now = new Date();

  let data = {
    // 登录用户
    user: {
      id: 1,
      name: "Coffce",
      img: "resource/image/default/201904/d202fcf3c660a682613ac0a06bd5e6f2.jpg"
    },

    // 用户列表
    userList: [
      {
        id: 2,
        name: "小明",
        img: "resource/image/default/201903/d86ea29bbf2719aa802f240f7823363b.jpeg",
        msg: "我的消息哪去了"
      },
      {
        id: 3,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 4,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 5,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 6,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 7,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 8,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      },
      {
        id: 9,
        name: "小花",
        img: "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1008891959,2261074863&fm=58",
        msg: "在这呢"
      }
    ],

    // 会话列表
    sessionList: [
      {
        userId: 2,
        messages: [
          {
            text: "Hello，你好。",
            date: now
          },
          {
            text: "我的消息哪去了",
            date: now
          }
        ]
      },
      {
        userId: 3,
        messages: [
          {
            text: "Hello，我在哪。",
            date: now
          },
          {
            text: "在这呢",
            date: now
          }
        ]
      }
    ]
  };

  localStorage.setItem(key, JSON.stringify(data));
}

export default {
  fetch() {
    return JSON.parse(localStorage.getItem(key));
  },
  save(store) {
    localStorage.setItem(key, JSON.stringify(store));
  }
};
